home *** CD-ROM | disk | FTP | other *** search
/ PC Pro 2003 March / DPPCPRO0303.ISO / Components / Microsoft ASP / _SETUP.1 / ASPWizard.jar / asp / wizard / WizardModelDbConnection.class (.txt) < prev    next >
Encoding:
Java Class File  |  1998-11-20  |  5.4 KB  |  139 lines

  1. package asp.wizard;
  2.  
  3. import asp.netobjects.nfx.util.ExceptionHandler;
  4. import asp.netobjects.nfx.util.ExternalError;
  5. import asp.netobjects.nfx.util.InternalError;
  6. import asp.netobjects.nfx.wizard.Wizard;
  7. import asp.netobjects.nfx.wizard.WizardPage;
  8. import asp.netobjects.nfx.wizard.WizardPageView;
  9. import asp.util.ResourceUtil;
  10. import asp.wizard.def.DefConnection;
  11. import com.sun.java.swing.ImageIcon;
  12. import java.sql.Connection;
  13.  
  14. public class WizardModelDbConnection extends WizardModelAbstract {
  15.    private DefConnection _defConnection;
  16.    private boolean _defExists = false;
  17.    public static final String ERR_DS_INVALID = "error.ds_invalid";
  18.    public static final String ERR_DSTYPE_INVALID = "error.dstype_invalid";
  19.    public static final String ERR_CONN_INVALID_REQD = "error.conn_invalid_reqd";
  20.    public static final String ERR_CONN_VALID = "msg.conn_valid";
  21.    public static final String ERR_CONN_INVALID = "error.conn_invalid";
  22.    // $FF: synthetic field
  23.    static Class class$asp$wizard$WVPanelDbConnection;
  24.  
  25.    public void commit() throws InternalError, ExternalError {
  26.       WizardViewDbConnection view = (WizardViewDbConnection)((WizardPage)this).getView();
  27.       if (this._defConnection == null) {
  28.          this._defConnection = new DefConnection();
  29.          String name = ((WizardModelAbstract)this).getDefPage().getUniqueNameFor(this._defConnection);
  30.          this._defConnection.setName(name);
  31.          ((WizardModelAbstract)this).getDefPage().addElement(this._defConnection);
  32.       }
  33.  
  34.       this._defConnection.setOdbcType(view.getOdbcType());
  35.       this._defConnection.setDSNName(view.getDSNName());
  36.       this._defConnection.setUserName(view.getUserName());
  37.       this._defConnection.setPassword(view.getPassword());
  38.       this._defConnection.setGlobalConnection(view.getGlobalConnection());
  39.    }
  40.  
  41.    public void loadValues() {
  42.       WizardViewDbConnection view = (WizardViewDbConnection)((WizardPage)this).getView();
  43.       if (this._defConnection == null) {
  44.          view.setDSNName("");
  45.          view.setUserName("");
  46.          view.setPassword("");
  47.          view.setGlobalConnection(view.getGlobalConnection());
  48.       } else {
  49.          view.setDSNName(this._defConnection.getDSNName());
  50.          view.setUserName(this._defConnection.getUserName());
  51.          view.setPassword(this._defConnection.getPassword());
  52.          view.setGlobalConnection(this._defConnection.getGlobalConnection());
  53.       }
  54.  
  55.    }
  56.  
  57.    public void loadView() {
  58.       WizardViewDbConnection view = (WizardViewDbConnection)((WizardPage)this).getView();
  59.       view.updateDataSources();
  60.       this.loadValues();
  61.    }
  62.  
  63.    public void validate() throws InternalError, ExternalError {
  64.       super.validate();
  65.       WizardViewDbConnection view = (WizardViewDbConnection)((WizardPage)this).getView();
  66.       if (view != null && !view.getDSNName().equals("")) {
  67.          if (view.getOdbcType() == -1) {
  68.             String err = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbConnection != null ? class$asp$wizard$WVPanelDbConnection : (class$asp$wizard$WVPanelDbConnection = class$("asp.wizard.WVPanelDbConnection")), "error.dstype_invalid");
  69.             throw new ExternalError(err);
  70.          } else {
  71.             try {
  72.                Connection _conn = this.getConnection();
  73.             } catch (EWizDbManager e) {
  74.                String err = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbConnection != null ? class$asp$wizard$WVPanelDbConnection : (class$asp$wizard$WVPanelDbConnection = class$("asp.wizard.WVPanelDbConnection")), "error.conn_invalid_reqd");
  75.                throw new ExternalError(err + " " + ((Throwable)e).getMessage());
  76.             }
  77.          }
  78.       } else {
  79.          String err = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbConnection != null ? class$asp$wizard$WVPanelDbConnection : (class$asp$wizard$WVPanelDbConnection = class$("asp.wizard.WVPanelDbConnection")), "error.ds_invalid");
  80.          throw new ExternalError(err);
  81.       }
  82.    }
  83.  
  84.    public Connection getConnection() throws EWizDbManager {
  85.       WizardViewDbConnection view = (WizardViewDbConnection)((WizardPage)this).getView();
  86.       Connection myConn = null;
  87.  
  88.       try {
  89.          WizDbManager WDBM = WizDbManager.getInstance();
  90.          myConn = WDBM.getConnection(view.getDSNName(), view.getUserName(), view.getPassword());
  91.          return myConn;
  92.       } catch (EWizDbManager e) {
  93.          throw new EWizDbManager(((Throwable)e).getMessage());
  94.       }
  95.    }
  96.  
  97.    public void testConnection() {
  98.       String err = null;
  99.  
  100.       try {
  101.          this.getConnection();
  102.          err = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbConnection != null ? class$asp$wizard$WVPanelDbConnection : (class$asp$wizard$WVPanelDbConnection = class$("asp.wizard.WVPanelDbConnection")), "msg.conn_valid");
  103.          AspWizardExceptionHandler.showMessage(1, err);
  104.       } catch (EWizDbManager e) {
  105.          err = ResourceUtil.getResourceString("asp.wizard.res", class$asp$wizard$WVPanelDbConnection != null ? class$asp$wizard$WVPanelDbConnection : (class$asp$wizard$WVPanelDbConnection = class$("asp.wizard.WVPanelDbConnection")), "error.conn_invalid");
  106.          AspWizardExceptionHandler.showMessage(0, ((Throwable)e).getMessage());
  107.       }
  108.  
  109.    }
  110.  
  111.    public WizardModelDbConnection() {
  112.    }
  113.  
  114.    public WizardModelDbConnection(Wizard wizard, String bullet, String info, ImageIcon icon, ExceptionHandler handler) {
  115.       super(wizard, bullet, info, icon, handler);
  116.    }
  117.  
  118.    protected WizardPageView getViewSingleInstance() {
  119.       return WizardViewDbConnection.getInstance();
  120.    }
  121.  
  122.    public DefConnection getDefConnection() {
  123.       return this._defConnection;
  124.    }
  125.  
  126.    public void setDefConnection(DefConnection dc) {
  127.       this._defConnection = dc;
  128.    }
  129.  
  130.    // $FF: synthetic method
  131.    static Class class$(String class$) {
  132.       try {
  133.          return Class.forName(class$);
  134.       } catch (ClassNotFoundException forName) {
  135.          throw new NoClassDefFoundError(((Throwable)forName).getMessage());
  136.       }
  137.    }
  138. }
  139.